<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title>view/workArea/parts/transferParts</title>
		<!-- css代码 start -->
		<link href="../../../css/mui.min.css" rel="stylesheet" />
		<link href="../../../css/global.css" rel="stylesheet" />
		<link href="../../../css/style.css" rel="stylesheet" />
		<link href="../../../css/checkbox.css" rel="stylesheet" />
		<link rel="stylesheet" href="../../../css/mui.picker.css">
		<link rel="stylesheet" href="../../../css/mui.poppicker.css">
		<link href="../../../css/task.css" rel="stylesheet" />
		<style>
			.d_int_tp{
				border: 0 !important;
				margin-top: 6px !important;
			}
			.mui-checkbox input[type=checkbox], .mui-radio input[type=radio]{
				top: 8px;
				right: -10px;
			}
			
			#div {
				width: 0px;
				height: 0px;
				background: red;
				position: fixed;
				top: 65%;
				left: 50%;
			}
			
			/*移除底部或顶部三角,需要在删除此代码*/
			.mui-popover .mui-popover-arrow:after {
				width: 0px;
			}
			
			.sel{
				font-size: 12px;
				margin-left: 10px;
				color: #ffffff;
				background: #ea1e1a;
				height: 20px;
				line-height: 12px !important;
				margin-top: 16px;
				border-radius: 5px;
				padding: 5px;
			}
			
			.item_box .item .text{
				padding: 0 17px;
				height: auto;
				line-height: 30px;
				font-size: 14px;
				word-wrap:break-word;
			}
			.mui-bar-nav{
				box-shadow: 0 1px 6px #ea1e1a;
			}
			.fixed {
				width: 100%;
				margin: 0;
				padding: 10px 20px 30px;
				background: #fcfdfe;
				box-shadow: 0 0 10px rgba(0,0,0,0.2);
				position: fixed;
				bottom: 0;
			}
		</style>
		<!-- css代码 end -->
	</head>
	<body>
		
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">备件转移</h1>
		</header>
		
		<!-- 弹窗 -->
		<div id="div"></div><!-- 只能是id="div" -->
		<div id="custNamePopover" class="mui-popover shadow popover">
			<ul class="mui-table-view" id="custNameLis">
				
			</ul>
		</div>
		
		
		<div class="mui-content">
			<div class="details_con select_con" id="search">
				<input type="hidden" id="new_enginner_id" />
				<div class="clum">
					<input type="text" class="d_int_tp" id="enginnerName" placeholder="请选择工程师" readonly="readonly" style="background: #ea1e1a;border: 0;color: #ddd;"/>
				</div>
				<div class="clum">
					<input type="text" class="d_int_tp" id="Remark" placeholder="请输入转移备注" />
				</div>
				<div style="height: 20px;"></div>
			</div>
			
			<div class="details_con" style="margin: 30px 0 0 0; padding-bottom: 80px;">
				<div class="item_box" id="itemBox">
					<!-- <div class="item">
						<div class="bar">
							<span class="number">1170001<img src="../../../images/icon_80.png" /></span>
							<div class="checkbox">
								<div class="mui-input-row mui-checkbox"> 
									<input name="checkbox1" part_id="id1" part_no="no2" value="运动" type="checkbox" class="rdss"/> 
									<label></label> 
								</div> 
							</div>
						</div>
						<div class="text">
							<span class="l">备件名称：</span> 
							备件1
						</div>
						<div class="type">
							<p>数量：<span>12</span><img src="../../../images/icon_81.png"/></p>
							<p>用途：<span>替换</span><img src="../../../images/icon_90.png"/></p>
						</div>
					</div> -->
				</div>
				<div id="partChangeBtn" class="btn_box fixed" style="display: none;">
					<span class="fl red one" id="partChange">提交转移</span>
					<!-- <span class="fl red one" id="receivBtn">提交转移</span> -->
				</div>
			</div>
		</div>
		
		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/utils/h.js"></script>
		<script src="../../../js/constant.js"></script>
		<script src="../../../js/common.js"></script>
		<script src="../../../js/utils/base64.js"></script>
		<script src="../../../js/utils/md5.js"></script>
		<script src="../../../js/utils/sortMap.js"></script>
		<script src="../../../js/utils/http.js"></script>
		<script src="../../../js/app.js"></script>
		<!-- 基础js end -->
		<script src="../../../js/utils/rolldate.min.js"></script>
		<script src="../../../js/mui.picker.js"></script>
		<script src="../../../js/mui.poppicker.js"></script>

		<script type="text/javascript" charset="utf-8">
			
			window.addEventListener('customEvent', function(event){ 
				// mui.fire()传过来的额外的参数，在event.detail中；
				var detail = event.detail;
				var fseId = detail.fseId;
				var fseName = detail.fseName;
				h("#new_enginner_id").val(fseId);
				h("#enginnerName").val(fseName);
			});
			(function($, doc) {
				$.init();

				$.plusReady(function() {
					// 列表查询
					selectList();
					
					// 提交转移
					h("#partChange").tap(function() {
						var partArr = new Array();
						// 获取checkbox的值
						var ele = document.getElementsByName("checkbox1");
						for (var i = 0; i < ele.length; i++) {
							if(ele[i].checked){
								var part = {};
								part["part_id"] = ele[i].value;
								part["part_no"] = ele[i].getAttribute("part_no");
								part["Part_name"] = ele[i].getAttribute("part_name");
								part["Part_qty"] = ele[i].getAttribute("part_qty");
								part["change_qty"] = ele[i].getAttribute("part_qty");
								partArr.push(part);
							}
						}
						if (partArr.length === 0) {
							app.toast("请选择备件");
						} else {
							subChange(JSON.stringify(partArr));
						}
					});
					
					// 查询fse跳新页
					h('#enginnerName').tap(function() {
						document.activeElement.blur();
						app.hideSoftKeybord();
						app.jumpTo("/view/workArea/parts/selectFse.html", "view/workArea/parts/selectFse", {
						});
					});
					
					// 查询fse
					// h('#fseSelectBtn').tap(function() {
					// 	var enginnerName = h("#enginnerName").val();
					// 	document.activeElement.blur();
					// 	ajaxPost(BASE_URL + "cc/engineerManage/selectTeamFseLocal", {
					// 		"teamleaderId": app.getUser().teamleaderId,
					// 		"enginnerName": enginnerName
					// 	}, function(data) {
					// 		// console.log(JSON.stringify(data));
					// 		if (data.code == 200) { //查询成功
					// 			if (data.data.length == 0) {
					// 				app.toast("查询无结果");
					// 			} else {
					// 				toSelCustName(data.data);
					// 			}
					// 		} else { //查询失败
					// 			app.toast("查询失败");
					// 		}
					// 	}, function(errorMsg) {
					// 		console.log(errorMsg)
					// 	});
					// });
					
				});
			}(mui, document));
			
			// 弹窗——打开
			function toSelCustName(arr) {
				console.log(JSON.stringify(arr));
				// console.log(arr.length);
				// 内容
				var html = "";
				if (arr && arr.length > 0) {
					for (var i = 0; i < arr.length; i++) {
						html += '<li class="mui-table-view-cell">';
						html += '<a href="Javascript:;" onclick="showCust(\'' + arr[i].fseId + '\',\'' + arr[i].fseName + '\');">' +
							arr[i].fseName + '</a>';
						html += '</li>';
						
					}
				}
				h("#custNameLis").html(html);
				// 弹出
				mui("#custNamePopover").popover('toggle', document.getElementById("div"));
				return
			}
			
			// 弹窗——客户——回显
			function showCust(id, name) {
				h("#new_enginner_id").val(id);
				mui("#custNamePopover").popover('hide', document.getElementById("div"));
			}
			
			// 弹窗——关闭
			function closepop() {
				mui("#custNamePopover").popover('hide', document.getElementById("div"));
			}
			
			// 提交转移
			function subChange(partArrStr) {
				var enginner_id = app.getUser().enginnerId;
				var new_enginner_id = h("#new_enginner_id").val();
				if (new_enginner_id == "") {
					app.toast("请选择工程师");
					return false;
				}
				if (!h("#Remark").val()) {
					app.toast("请输入转移备注");
					return false;
				}
				
				ajaxPost(BASE_URL + "cc/spareParts/partChangeHandle",{
					"enginner_id": enginner_id,
					"new_enginner_id": new_enginner_id,
					"Remark": h("#Remark").val(),
					"partInfo": partArrStr
				},function(data) {
					if (data.code === 200) {
						var dataObj = JSON.parse(data.data);
						app.toast(dataObj.message);
						selectList();
					} else {
						app.toast(data.msg)
					}
				}, function(errorMsg) {
					app.toast(errorMsg)
				});
			}
			
			// 查询派单列表(使用post请求)
			function selectList(){
				var enginnerId = app.getUser().enginnerId;
				app.showWaiting('加载中...')
				ajaxPost(BASE_URL + "cc/spareParts/queryPartByFseIdPostZY",{
					"CustName": "",
					"Status": "5",
					"Part_no": "",
					"enginner_id": enginnerId
				},function(data) {
					app.closeWaiting()
					if (data.code === 200) {
						var str = '';
						var dataObj = JSON.parse(data.data);
						console.log(dataObj)
						var list = dataObj.record;
						// 无数据
						if (list.length == 0) {
							h("#itemBox").html('<div class="nodata">—— 暂无数据 ——</div>');
							h("#partChangeBtn").hide();
							return false;
						}
						// 显示列表
						for(var i = 0; i<list.length; i++){
							var info = list[i];
							str += '<div class="item">';
							str += '<div class="bar">';
							str += '<span class="number">'+ info.Part_no +'<img src="../../../images/icon_204.png" /></span>';
							str += '<div class="checkbox">';
							str += '<div class="mui-input-row mui-checkbox"> ';
							
							str += '<input name="checkbox1" value="'+ info.Part_id +'" part_no="'+ info.Part_no +'" part_name="'+ info.Part_name +'" part_qty="'+ info.Part_qty +'" type="checkbox" class="rdss"/> ';
							str += '<label></label> ';
							str += '</div> ';
							str += '</div>';
							str += '</div>';
							str += '<div class="text">';
							str += '<span class="l">备件名称：</span> '+ info.Part_name;
							str += '</div>';
							str += '<div class="type">';
							str += '<p>数量：<span>'+ info.Part_qty +'</span><img src="../../../images/icon_217.png"/></p>';
							str += '<p>用途：<span>'+ emptyStr(info.UseType) +'</span><img src="../../../images/icon_203.png"/></p>';
							str += '</div>';
							str += '</div>';
						}
						h('#itemBox').html(str);
						h("#partChangeBtn").show();
					} else {
						h("#itemBox").html('<div class="nodata">—— 暂无数据 ——</div>');
						h("#partChangeBtn").hide();
						app.toast(data.msg)
					}
				}, function(errorMsg) {
					app.closeWaiting()
					h("#itemBox").html('<div class="nodata">—— 暂无数据 ——</div>');
					h("#partChangeBtn").hide();
					app.toast("数据获取失败，请检查网络连接");
				});
			}
		</script>
		<!-- js代码 end -->
	</body>
</html>
